package cn.bluemobi.platform.controller.banner;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.bluemobi.common.core.dto.MapDto;
import cn.bluemobi.common.core.dto.PageCondition;
import cn.bluemobi.platform.core.controller.PlatformBaseController;
import cn.bluemobi.platform.core.dto.DatatablePage;
import cn.bluemobi.platform.entity.banner.Banner;
import cn.bluemobi.platform.service.BannerService;

/**
 * 
 * @author qifnagke
 * 
 */
@Controller
@RequestMapping("/admin/banner")
public class BannerController extends PlatformBaseController {

	@Autowired
	private BannerService bannerService;

	@RequestMapping("/findCommodityList")
	@ResponseBody
	public List<Map<String, Object>> findCommodityList() {
		return bannerService.findCommodityList();
	}

	@RequestMapping("/toBannerPage")
	public String toBannerPage(ModelMap model) {
		return "banner/bannerList";
	}

	@RequestMapping("/findBanners")
	@ResponseBody
	public DatatablePage findBanners(PageCondition cond) {
		return new DatatablePage(cond, bannerService.findBanners(cond));
	}

	@RequestMapping("/toBannerDetailPage")
	public String toBannerDetailPage(
			@RequestParam(value = "bannerId", required = false) String bannerId,
			ModelMap model) {
		if (!StringUtils.isEmpty(bannerId)) {
			Banner banner = bannerService.findBannerDetail(bannerId);
			model.put("banner", banner);
		}
		return "banner/bannerDetail";
	}

	@RequestMapping("/saveBanner")
	@ResponseBody
	public MapDto saveBanner(Banner banner) {
		return bannerService.saveOrUpdate(banner, getUser());
	}

	@RequestMapping("/deleteBanner")
	@ResponseBody
	public MapDto deleteBanner(@RequestParam("bannerId") String bannerId) {
		return bannerService.deleteBanner(bannerId, getUser());
	}

}
